// store/modules/app.ts
import { defineStore } from "pinia";

type TabID = "session" | "chat" | "discover" | "profile";

interface Background {
  id: "bg1" | "bg2" | "bg3";
  name: string;
  blur: number;
}

interface AppState {
  currentTab: TabID;
  backgroundIndex: number;
  backgrounds: Background[];
  showDownloadPanel: boolean;
}

export const useAppStore = defineStore("app", {
  state: (): AppState => ({
    currentTab: "session", // 设置默认标签页
    backgroundIndex: 0,
    backgrounds: [
      { id: "bg1", name: "默认背景", blur: 5 },
      { id: "bg2", name: "主题背景A", blur: 8 },
      { id: "bg3", name: "主题背景B", blur: 6 },
    ],
    showDownloadPanel: false,
  }),

  actions: {
    // 添加或更新切换标签页的方法
    changeTab(tabId: TabID) {
      this.currentTab = tabId;
      console.log("Tab switched to:", tabId);
    },

    setBackground(index: number) {
      this.backgroundIndex = index;
    },

    toggleDownloadPanel() {
      this.showDownloadPanel = !this.showDownloadPanel;
    },

    switchBackground() {
      this.backgroundIndex =
        (this.backgroundIndex + 1) % this.backgrounds.length;
    },
  },

  getters: {
    currentBackground: (state) => state.backgrounds[state.backgroundIndex],
    currentTab: (state) => state.currentTab,
  },
});
